{*
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 *}
{script src='js/attachment.js'}
<script type="text/javascript">
<!--
var agora_preview_url = '{url task=post page=topic action=preview format=raw}';
var empty_desc = '##Enter a brief description of your topic##';
{literal}
function agora_preview() {

	var ticon = 0;
	$$('input[name=topic_icon]').each(function(el,index){
		if(el.checked){
			ticon = el.value
		}
	});

	var preview_data = {
		req_message: ($$('textarea[name=req_message]').getValue()).toString(),
		topic_icon: ticon,
		subject: ($$('input[name=subject]').getValue()).toString(),
		desc: ($$('input[name=desc]').getValue()).toString(),
		hide_smilies: ($$('input[name=hide_smilies]').getValue()).toString(),
	};

	if (preview_data.desc == empty_desc) {
		preview_data.desc = '';
	}

	if (!$$('input[name=hide_smilies]').getProperty('checked')) {
		preview_data.hide_smilies = 0;
	}

	new Ajax(agora_preview_url, {
			method: 'post',
			data: preview_data,
			onFailure: function(){},
			onComplete: function(inResponse) {
				var box = SqueezeBox.initialize();
				box.assignOptions();
				box.setContent('string',inResponse);
			}
	}).request();
}

function populate_hidden() {
	if($('upload').value) {
		var ticon = 0;
		$$('input[name=topic_icon]').each(function(el,index){
			if(el.checked){
				ticon = el.value
			}
		});
		{/literal}{if !empty($topic_userid)}{literal}
			document.getElementById('userid_hidden').value = escape(($$('input[name=topic_userid]').getValue()).toString());
			document.getElementById('username_hidden').value = escape(($$('input[name=topic_username]').getValue()).toString());
		{/literal}{/if}{literal}
		document.getElementById('id_hidden').value = escape(($$('input[name=id]').getValue()).toString());
		document.getElementById('msg_hidden').value = escape(($$('textarea[name=req_message]').getValue()).toString());
		document.getElementById('subject_hidden').value = escape(($$('input[name=subject]').getValue()).toString());
		document.getElementById('desc_hidden').value = escape(($$('input[name=desc]').getValue()).toString());
		document.getElementById('smilies_hidden').value = escape(($$('input[name=hide_smilies]').getValue()).toString());
		document.getElementById('ticon_hidden').value = escape(ticon);
		document.uploadform.submit();
	} else {
		alert('Please choose a file');
	}
}
{/literal}
//-->
</script>

<div class="ag_rightend">
	<h2 class="ag_headerbar"><span class="ag_middle">##New thread##</span></h2>
</div>
<div class="ag_outerwrap">
	<form id="post" method="post" name="post" action="{url task=post page=topic action=save id=$cur_forum_id}" onsubmit="if (this.desc.value=='##Enter a brief description of your topic##') this.desc.value=''">
		<input type="hidden" name="id" id="id" value="{$cur_forum_id}" />
		<fieldset class="ag_inform">
			<legend class="ag_color">##Write message legend##</legend>
			{if count($topic_icons) > 1}
			<ul class="ag_topic_icons">
				{foreach from=$topic_icons item=icon}
				<li>
					<span><img src="{image src=icons/$icon.png}" alt="{$icon}" /></span>
					<input type="radio" name="topic_icon" value="{$icon}" />
				</li>
				{/foreach}
				<li>
					<span><img src="{image src=icons/info.png}" alt="0" /></span>
					<input type="radio" name="topic_icon" value="0" checked="checked" />
				</li>
			</ul>
			{/if}
			<div class="ag_clearer"></div><br />
			<label for="subject" class="ag_label">
				<strong>##Subject##:</strong>
				<input class="required subject ag_text_area2" id="subject" title="##Pleaseentertext##" style="width:99%;" type="text" name="subject" size="80" maxlength="70" onkeydown='textCount(document.post.subject,document.post.characterstyped_2,70);' onkeyup='textCount(document.post.subject,document.post.characterstyped_2,70);' tabindex="1" />
			</label>
			<div class="ag_characterstyped">
				<input class="ag_characterstyped" readonly="readonly" type="text" name="characterstyped_2" size="4" maxlength="4" value="70" />##characters##
			</div>
			<br />
			<label for="desc" class="ag_label">
				<strong>##Description##:</strong>
				<input class="longinput ag_text_area2" type="text" id="desc" name="desc" size="80" style="width:99%;" maxlength="70" value="##Enter a brief description of your topic##" onblur="if(this.value=='') this.value='##Enter a brief description of your topic##';" onfocus="if(this.value=='##Enter a brief description of your topic##') this.value='';" tabindex="2" />
			</label>
			<div class="ag_clearer"></div><br />
			{include file=agora:post/post.tpl}
			{if $agora_user.id eq '0'}
			<label>
				##Email##
				<input name="email" class="email required" type="text" value="" />
			</label>
			{/if}
		</fieldset>
		{if !empty($plugin_template)}
			{$plugin_template}
		{/if}
		<fieldset class="ag_inform">
			<legend class="ag_color">##Options##</legend>
			<div class="ag_infldset">
				<label>
					<input type="checkbox" name="hide_smilies" value="1" />##Hide smilies##
				</label>
				<br />
				<label>
					<input type="checkbox" name="subscribe" value="1" {if $agora_config.o_auto_subscriptions and $agora_user.auto_subscriptions}checked="checked"{/if} />##Subscribe##
				</label>
			</div>
		</fieldset>
		<div class="ag_postbuttons">
			<span>
				<input class="ag_button ag_btn_submit" type="submit" name="submit" value="##Submit##" title="##Submit##" accesskey="s" tabindex="5" />
				<input class="ag_button ag_btn_preview" type="button" name="preview" value="##Preview##" title="##Preview##" accesskey="p" onclick="agora_preview()" tabindex="4" />
				&nbsp;##or##&nbsp;
				<a href="javascript:void(0);" class="ag_btn_goback" title="##Go back##" onclick="javascript:history.go(-1)" tabindex="6">##Go back##</a>
			</span>
		</div>
	</form>
	{if $agora_config.o_allow_attach eq '1' and $agora_config.o_attach_type eq '0' and $agora_user.id}
	<form id="uploadform" name="uploadform" method="post" action="{url task=upload action=add redir=self}" onsubmit="populate_hidden();return false;" enctype="multipart/form-data">	
		<fieldset class="ag_inform">
			<legend class="ag_color">##Attachment##</legend>
			<div class="ag_infldset">
				<input type="file" id="upload" name="upload" style="width:99%;" />
				<input class="ag_button ag_btn_submit" type="submit" name="sbm" value="##Upload##" title="##Upload##" />
				<input type="hidden" name="id_hidden" id="id_hidden" value="" />
				<input type="hidden" name="msg_hidden" id="msg_hidden" value="" />
				<input type="hidden" name="userid_hidden" id="userid_hidden" value="" />
				<input type="hidden" name="username_hidden" id="username_hidden" value="" />
				<input type="hidden" name="ticon_hidden" id="ticon_hidden" value="" />
				<input type="hidden" name="smilies_hidden" id="smilies_hidden" value="" />
				<input type="hidden" name="subject_hidden" id="subject_hidden" value="" />
				<input type="hidden" name="desc_hidden" id="desc_hidden" value="" />
			</div>
		</fieldset>
	</form>
	{/if}
	<script type="text/javascript">
	<!--
	{literal}
	window.addEvent('domready', function(){
		var myFormValidation = new Validate('post',{
			errorClass: 'red',
			label: '##Please wait##'
		});
	});
	{/literal}
	//-->
	</script>
	<script type="text/javascript">
	<!--
	{if isset($smarty.session.form_hidden)}
		{if !empty($topic_userid)}
			document.getElementById('topic_userid').value = unescape('{$smarty.session.form_hidden.userid}');
			document.getElementById('topic_username').value = unescape('{$smarty.session.form_hidden.username}');
		{/if}
		document.getElementById('id').value = unescape('{$smarty.session.form_hidden.id}');
		document.getElementById('req_message').innerHTML = unescape('{$smarty.session.form_hidden.message}');
		document.getElementById('subject').value = unescape('{$smarty.session.form_hidden.subject}');
		document.getElementById('desc').value = unescape('{$smarty.session.form_hidden.desc}');
		document.getElementById('hide_smilies').value = unescape('{$smarty.session.form_hidden.smilies}');
		
		var tpicon = unescape('{$smarty.session.form_hidden.ticon}');
		{literal}
		$$('input[name=topic_icon]').each(function(el,index){
			if(el.value == tpicon) {
				el.checked = true;
			}
		});
		{/literal}
		{php} unset($_SESSION['form_hidden']); {/php}
	{/if}
	{if isset($smarty.session.add_attachment)}
		image('{$smarty.session.add_attachment.path}','{$smarty.session.add_attachment.name}','{$smarty.session.add_attachment.mini}','{$smarty.session.add_attachment.width}','{$smarty.session.add_attachment.height}');
		{php} unset($_SESSION['add_attachment']); {/php}
	{/if}
	//-->
	</script>
</div>